<template>
  <view class="popup-mask" v-if="modelValue" @click="handleMaskClick">
    <view 
      class="popup-content" 
      :class="type"
      @click.stop
      :style="{ height: height }"
    >
      <slot></slot>
    </view>
  </view>
</template>

<script>
export default {
  name: 'Popup',
  props: {
    modelValue: {
      type: Boolean,
      default: false
    },
    type: {
      type: String,
      default: 'bottom'
    },
    height: {
      type: String,
      default: 'auto'
    },
    maskClosable: {
      type: Boolean,
      default: true
    }
  },
  methods: {
    handleMaskClick() {
      if (this.maskClosable) {
        this.$emit('update:modelValue', false)
      }
    }
  }
}
</script>

<style>
.popup-mask {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
}

.popup-content {
  position: fixed;
  background: #fff;
  transition: all 0.3s;
}

.popup-content.bottom {
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 24rpx 24rpx 0 0;
  transform: translateY(0);
  padding-bottom: env(safe-area-inset-bottom);
}
</style> 